package ibmetp.mis.controller.code;

import ibmetp.mis.common.Constants;
import ibmetp.mis.common.Message;
import ibmetp.mis.service.CodeTypeService;
import ibmetp.mis.serviceImpl.CodeTypeServiceImpl;
import ibmetp.mis.vo.CodeType;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

/**
 * Servlet implementation class CodeTypeAddServlet
 */
public class CodeTypeAddServlet extends HttpServlet {
	
	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding(Constants.ENCODING_UTF8);
		System.out.println("Call CodeTypeAddServlet...");
		
		//获取代码类型
		CodeType codetype=new CodeType();
		//codetype.setCodeTypeId(Long.parseLong(request.getParameter("codeTypeId")));
		codetype.setCodeTypeName(request.getParameter("codeTypeName"));
		codetype.setDescript(request.getParameter("descript"));
		
		//添加代码类型
		CodeTypeService ss=(CodeTypeService) new CodeTypeServiceImpl();
		String result=ss.addCodeType(codetype);
		
		//如果有返回消息，则将消息发回页面
		if(result!=null){		
			response.setCharacterEncoding(Constants.ENCODING_UTF8);
			response.getWriter().print(JSONObject.fromObject(new Message(result)));
		}
	}
}
